package hu.szyrt.bug.connections;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.json.JSONException;
import org.json.JSONObject;

import hu.szyrt.bug.utils.Config;

public class CommentSendConnection extends BaseConnection {

	//2012-08-10 02:22:09
	private final static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	
	public CommentSendConnection() {
		super(Config.URL_BUG_COMMENT_SEND);
	}

	@Override
	public void run() {
		parameterizedURL();
		if(download()){
			// JSON decode
			try {
				JSONObject jsonResult = new JSONObject(rawResults);
				if(jsonResult.getString("result").equals("OK"))
					postSuccess();
				else 
					postError();
			} catch (JSONException e) {
				e.printStackTrace();
				postError();
			}
		}else{
			postError();
		}
	}
	
	public void setDate(String date){
		params.put("date", date);
	}
	
	public void setDate(Date date){
		params.put("date", dateFormat.format(date));
	}
	
	public void setPlaceID(int id){
		params.put("place_id", String.valueOf(id));
	}
	
	public void setMemberID(int id){
		params.put("member_id", String.valueOf(id));
	}
	
	public void setComment(String comment){
		params.put("comment", comment);
	}
	
}
